<%@ Page Language="C#" MasterPageFile="~/Base.Master" AutoEventWireup="true" CodeBehind="CompaniesAccounts.aspx.cs" Inherits="SVAccountingWebUI.CompaniesAccounts" %>
<%@ MasterType VirtualPath="~/Base.Master" %>

<asp:Content ID="CompaniesAccountsContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False"  
        DataKeyNames="AccountID" DataSourceID="ComapniesAccountsLinqDataSource" 
        onrowdeleting="gv_RowDeleting" 
        OnRowEditing="gv_RowEditing" onrowcancelingedit="gv_RowCancelingEdit" 
        >
        <Columns>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, EditDelete %>">
                <EditItemTemplate>
                &nbsp;
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" ImageUrl="~/Icons/Update.png" Text="Update" />
                    /&nbsp;<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" ImageUrl="~/Icons/Cancel.png" Text="Cancel" />
                </EditItemTemplate>
                <ItemTemplate>
                &nbsp;
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" ImageUrl="~/Icons/Edit.png" Text="Edit" />
                    /&nbsp;<asp:ImageButton ID="DeleteButton" runat="server" CausesValidation="False" 
                        CommandName="Delete" ImageUrl="~/Icons/delete.png" Text="Delete"
                        message="<%$ Resources:Resource, DeleteConfirm %>" 
                        OnClientClick='return confirm(this.getAttribute("message"))'
                        />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="AccountID" HeaderText="<%$ Resources:Resource, ID%>" ReadOnly="True" 
                SortExpression="AccountID" />

            <asp:TemplateField SortExpression="CompanyID" HeaderText="<%$ Resources:Resource, Company%>">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="LinqDataSource1" DataTextField="CompanyName" 
                        DataValueField="CompanyID" SelectedValue='<%# Bind("CompanyID") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Company.CompanyName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="BankName" HeaderText="<%$ Resources:Resource, Bank%>" 
                SortExpression="BankName" />
            <asp:BoundField DataField="AccountCode" HeaderText="<%$ Resources:Resource, AccountCode%>" 
                SortExpression="AccountCode" />
            <asp:BoundField DataField="DateCreated" HeaderText="<%$ Resources:Resource, CreatedDate%>" 
                SortExpression="DateCreated" />
            <asp:BoundField DataField="AccountType" HeaderText="<%$ Resources:Resource, AccountType%>" 
                SortExpression="AccountType" />
            <asp:CheckBoxField DataField="IsActive" HeaderText="<%$ Resources:Resource, IsActive%>" 
                SortExpression="IsActive" />
            <asp:CheckBoxField DataField="IsDefault" HeaderText="<%$ Resources:Resource, IsDefault%>" 
                SortExpression="IsDefault" />
        </Columns>
        <FooterStyle BackColor="#CCCCCC" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#CCCCCC" />
    </asp:GridView>
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        ContextTypeName="SVAccountingBL.SVALinqDataContext" 
        Select="new (CompanyID, CompanyName)" TableName="Companies">
    </asp:LinqDataSource>
    <asp:LinqDataSource ID="ComapniesAccountsLinqDataSource" runat="server" 
        ContextTypeName="SVAccountingBL.SVALinqDataContext" EnableDelete="True" 
        EnableInsert="True" EnableUpdate="True" TableName="CompanyAccounts" 
        ondeleted="LinqDataSource_Deleted" 
        oninserted="LinqDataSource_Inserted" 
        oninserting="LinqDataSource_Inserting" 
        onupdated="LinqDataSource_Updated">
    </asp:LinqDataSource>
    
   <asp:UpdatePanel ID="AddNewPanel" runat="server">
   <ContentTemplate>
    <br />
    <asp:LinkButton ID="lbtnAddNew" runat="server" 
                    Text="<%$ Resources:Resource, AddNew %>" 
           onclick="AddNew_Click"/>
    <br />
    <br />
     <div ID="InsertDiv" runat="server" visible="false">
    <asp:DetailsView ID="dvCompaniesAccounts" runat="server" Height="50px" Width="125px" 
           AutoGenerateRows="False" CellPadding="4" DataKeyNames="AccountID" 
           DataSourceID="ComapniesAccountsLinqDataSource" DefaultMode="Insert" 
           ForeColor="#333333" GridLines="None"
           OnItemCommand = "InsertDV_ItemCommand"
           >
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="AccountID" HeaderText="AccountID" ReadOnly="True" 
                SortExpression="AccountID" InsertVisible="false" />
            <asp:TemplateField HeaderText="CompanyID" SortExpression="CompanyID">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CompanyID") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" 
                        DataSourceID="LinqDataSource1" DataTextField="CompanyName" 
                        DataValueField="CompanyID" SelectedValue='<%# Bind("CompanyID") %>'>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("CompanyID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="BankName" SortExpression="BankName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("BankName") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                <table>
                <tr>
                <td><asp:TextBox ID="txtBankName" runat="server" Text='<%# Bind("BankName") %>'></asp:TextBox></td>
                <td><asp:RequiredFieldValidator ID="rfvBankName" ControlToValidate="txtBankName" runat="server" ErrorMessage="*" EnableClientScript="true" /></td>
                </tr>
                </table>
                    
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("BankName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="AccountCode" SortExpression="AccountCode">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("AccountCode") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                <table>
                <tr>
                <td><asp:TextBox ID="txtAccountCode" runat="server" Text='<%# Bind("AccountCode") %>'></asp:TextBox></td>
                <td><asp:RequiredFieldValidator ID="rfvAccountCode" ControlToValidate="txtAccountCode" runat="server" ErrorMessage="*" EnableClientScript="true" /></td>
                </tr>
                </table>
                    
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("AccountCode") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="AccountType" SortExpression="AccountType">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("AccountType") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                <table>
                <tr>
                <td><asp:TextBox ID="txtAccountType" runat="server" Text='<%# Bind("AccountType") %>'></asp:TextBox></td>
                <td><asp:RequiredFieldValidator ID="rfvAccountType" ControlToValidate="txtAccountType" runat="server" ErrorMessage="*" EnableClientScript="true" /></td>
                </tr>
                </table>
                    
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("AccountType") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CheckBoxField DataField="IsActive" HeaderText="IsActive" 
                SortExpression="IsActive" />
            <asp:CheckBoxField DataField="IsDefault" HeaderText="IsDefault" 
                SortExpression="IsDefault" />
            <asp:CommandField ButtonType="Image" CancelImageUrl="~/Icons/Cancel.png" 
                InsertImageUrl="~/Icons/Add.png" ShowInsertButton="True" />
        </Fields>
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
       </asp:DetailsView>
       </div>
    </ContentTemplate>
    
      <Triggers>
         <asp:AsyncPostBackTrigger ControlID="lbtnAddNew" EventName="click" />
         <asp:PostBackTrigger ControlID="dvCompaniesAccounts" /> 
    </Triggers>
    
    
    </asp:UpdatePanel>

</asp:Content>